package com.wzb.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzb.mybatisplus.bitaction.ArchiveThreadPool;
import com.wzb.mybatisplus.bitaction.BitcoinPrivateKeyGenerator1;
import com.wzb.mybatisplus.bitaction.BitcoinWIFConverter;
import com.wzb.mybatisplus.bitaction.electrumaction.FileUtils;
import com.wzb.mybatisplus.bitaction.electrumaction.five.WIFPrivateKeyGenerator;
import com.wzb.mybatisplus.bitaction.electrumaction.four.WIFPrivateKeyConverter;
import com.wzb.mybatisplus.bitaction.electrumaction.one.*;
import com.wzb.mybatisplus.bitaction.electrumaction.three.SendEmailToQQ;
import com.wzb.mybatisplus.bitaction.section.GetSection;
import com.wzb.mybatisplus.bitaction.section.GetSection1;
import com.wzb.mybatisplus.entity.Bituse;
import com.wzb.mybatisplus.entity.Sy;
import com.wzb.mybatisplus.entity.Syone;
import com.wzb.mybatisplus.entity.Sytwo;
import com.wzb.mybatisplus.mapper.BituseMapper;
import com.wzb.mybatisplus.mapper.SyMapper;
import com.wzb.mybatisplus.mapper.SyoneMapper;
import com.wzb.mybatisplus.mapper.SytwoMapper;
import com.wzb.mybatisplus.service.IBituseService;
import com.wzb.mybatisplus.service.ISyService;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.*;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.sql.SQLOutput;
import java.util.*;
import java.util.concurrent.locks.LockSupport;
@Slf4j
@Service
public class SyServiceImpl extends ServiceImpl<SyMapper, Sy> implements ISyService {

    @Autowired
    private SyoneMapper syoneMapper;

    @Autowired
    private SytwoMapper sytwoMapper;

    @Autowired
    private BituseMapper bituseMapper;

    public  List<Sy> sy1 =new ArrayList<>();
    public List<Syone> syones = new ArrayList<>();

    public List<Sytwo> sytwos = new ArrayList<>();


    private static int conutsum = 0;
    private static final NetworkParameters MAINNET = MainNetParams.get();
    private static int flag = 0;
    @Override
    public void suiji() throws InterruptedException {

        //遍历赋值
        addList();



//        int s = 571;
//        for(int j=1;j<=1000;j++){

//            String path = "D:\\btc\\miyao\\"+(1121+j)+".txt";
//            FileUtils fileUtils = new FileUtils();
//            fileUtils.createFile(path);
//        fileUtils.writeFile("赚钱","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");533
//        fileUtils.writeFile("破解","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");

            int sum = 0;
            // 生成多个私钥进行测试
            for (int i = 0; sum < 5000; i++) {
                BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey();
//                System.out.println("=== 私钥 #" + (i + 1) + " ===");
//                System.out.println(privateKey);
//                System.out.println("有效性检查: " +
//                        BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey()));
                if(BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())){

                    Sytwo sy = new Sytwo();
                    sy.setSy(privateKey.getWIFCompressed());
                    try{

                        if(aa(privateKey.getWIFCompressed())>=1){continue;}


                        sytwos.add(sy);
                        sytwoMapper.insert(sy);
                        JSONObject object = jine(privateKey.getWIFCompressed());

                        Long maney = object.getLong("final_balance");;
//                        Thread.sleep(1000);

                        long total_received = object.getLong("total_received");
                        long jiaoyiliang = object.getLong("n_tx");

                        if( maney>0.00000000000000  || jiaoyiliang > 0.0  || total_received >0.0 ){
                            System.out.println("=======金额======"+maney +"私钥："+privateKey.getWIFCompressed());

                            Bituse bituse = new Bituse();
                            bituse.setWifsy(privateKey.getWIFCompressed());
                            bituse.setMask(maney+"");
                            bituseMapper.insert(bituse);
                            if(maney>0.0){
                            System.exit(1);}

                        }
//                        fileUtils.writeFile( privateKey.getWIFCompressed()+"\n",path);
                        sum ++;
                    }catch (Exception e){
                        continue;
                    }

//                    Thread.sleep(500);
                }

            }
//        }

    }

    @Override
    public void huoquzhi() throws Exception {

        {

            //遍历赋值
//            addList();


//        int s = 571;
//        for(int j=1;j<=1000;j++){

            String path = "D:\\btc\\miyao\\maney.txt";
            FileUtils fileUtils = new FileUtils();
            fileUtils.createFile(path);
//        fileUtils.writeFile("赚钱","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");533
//        fileUtils.writeFile("破解","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");


            // 生成多个私钥进行测试
            for (int i = 0; conutsum < 5000; i++) {

//                ArchiveThreadPool.getThreadPoolInstance().execute(()->{
                    flag++;
//                    System.out.println("==============="+(flag));
                    BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey();

                    if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {


                        try {


                            JSONObject object = jine(privateKey.getWIFCompressed());

                            Long maney = object.getLong("final_balance");
                            ;
//                        Thread.sleep(1000);

                            long total_received = object.getLong("total_received");
                            long jiaoyiliang = object.getLong("n_tx");

                            if (maney > 0.0 || jiaoyiliang > 0.0 || total_received > 0.0) {
                                System.out.println("=======金额======" + maney + "私钥：" + privateKey.getWIFCompressed());
                                conutsum++;
                                Bituse bituse = new Bituse();
                                bituse.setWifsy(privateKey.getWIFCompressed());
                                bituse.setMask(maney + "");
                                bituseMapper.insert(bituse);
                                if (maney > 0.0) {
                                    System.exit(1);
                                }
                                fileUtils.writeFile( privateKey.getWIFCompressed()+"\n",path);

                            }
//                        fileUtils.writeFile( privateKey.getWIFCompressed()+"\n",path);
//                        sum++;
                        } catch (Exception e) {
//                            continue;
                        }

//                        Thread.sleep(500);
                    }



//                });


            }
//        }

        }
    }

    @Override
    public void addManeys() throws Exception {
        String path = "D:\\btc\\miyao\\maney.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        for (int i = 0; conutsum < 5000; i++){
            //随机生成私钥

            if(i>1000000){i=0;j++;}
            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey();
            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);
                addressesSys.add(wifPrivateKey);
            }

            if(addresses.size()>=300){


                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(;result==null;){
//                    Thread.sleep(1000);
//                    flag++;
//                    System.out.println("=======调用比特币地址返回空，走进死循环中了======="+flag);
                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                }
                JSONObject jsonResponse = new JSONObject(result);
                int z = 0;
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        List<String> listSys = new ArrayList<>();
                        listSys.addAll(addressesSys);
                        bituse.setWifsy(listSys.get(z));
                        bituse.setMask(maney + "");
                        bituseMapper.insert(bituse);
                        if(maney>0){
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com",listSys.get(z));

                            for(String s : addressesSys){
                                fileUtils.writeFile( s+"\n",path);
                            }
                            System.out.println();

                        }

                    }
                    z++;
                }
                addressesSys.clear();
                addresses.clear();
            }


        }



    }

    @Override
    public void addManeys1() throws Exception {
        String path = "D:\\btc\\miyao\\maney1.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        for (int i = 0; conutsum < 5000; i++){
            //随机生成私钥

            if(i>1000000){i=0;j++;}
            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey();
            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);
                addressesSys.add(wifPrivateKey);
            }

            if(addresses.size()>=300){


                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(;result==null;){
//                    Thread.sleep(1000);
//                    flag++;
//                    System.out.println("=======调用比特币地址返回空，走进死循环中了======="+flag);
                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                }
                JSONObject jsonResponse = new JSONObject(result);
                int z = 0;
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        List<String> listSys = new ArrayList<>();
                        listSys.addAll(addressesSys);
                        bituse.setWifsy(listSys.get(z));
                        bituse.setMask(maney + "");
                        bituseMapper.insert(bituse);
                        if(maney>0){
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com",listSys.get(z));

                            for(String s : addressesSys){
                                fileUtils.writeFile( s+"\n",path);
                            }
                            System.out.println();

                        }

                    }
                    z++;

                }
                addressesSys.clear();
                addresses.clear();
            }


        }



    }
    @Override
    public void addManeys2(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        for (int i = 0; conutsum < 5000; i++){
            //随机生成私钥

            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));

            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){
                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);
                addressesSys.add(wifPrivateKey);
            }
//                System.out.println(privateKey);
            sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
            if(addresses.size()>=300){


                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                List<String> listSys = new ArrayList<>();
                listSys.addAll(addressesSys);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(;result==null;){
//                    Thread.sleep(1000);
//                    flag++;
//                    System.out.println("=======调用比特币地址返回空，走进死循环中了======="+flag);
                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                }
                JSONObject jsonResponse = new JSONObject(result);
                int z = 0;
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(listSys.get(z));
                        bituse.setMask(maney + "  ,   " +addressesSys);
                        bituseMapper.insert(bituse);
                        System.out.println("=======金额======" + maney + "私钥：" + listSys.get(z));
//                            bituseMapper.insert(bituse);
                        if(maney>0){
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com",addressesSys.toString());
                            SendEmailToQQ sendEmailToQQ1 = new SendEmailToQQ();
                            sendEmailToQQ1.sendEmail("2267457055@qq.com","有效值："+listSys.get(z));
                            String send = "";
                            for(String s : addressesSys){
                                fileUtils.writeFile( s+"\n",path);
                                send=send+"有效值："+s;
                            }
                            SendEmailToQQ sendEmailToQQ3 = new SendEmailToQQ();
                            sendEmailToQQ3.sendEmail("2267457055@qq.com",send);
                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                        fileUtils.writeFile( "有效值："+listSys.get(z)+"\n",path);
                    }
                    z++;
                }
                addressesSys.clear();
                addresses.clear();
            }


        }




    }
    @Override
    public void addManeys3(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        for (int i = 0; conutsum < 5000; i++){
            //随机生成私钥

            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));

            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){
                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);
                addressesSys.add(wifPrivateKey);
            }
//                System.out.println(privateKey);
            sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
            if(addresses.size()>=300){


                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                List<String> listSys = new ArrayList<>();
                listSys.addAll(addressesSys);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(;result==null;){
//                    Thread.sleep(1000);
//                    flag++;
//                    System.out.println("=======调用比特币地址返回空，走进死循环中了======="+flag);
                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                }
                JSONObject jsonResponse = new JSONObject(result);
                int z = 0;
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(listSys.get(z));
                        bituse.setMask(maney + "  ,   " +addressesSys);
                        bituseMapper.insert(bituse);
                        System.out.println("=======金额======" + maney + "私钥：" + listSys.get(z));
//                            bituseMapper.insert(bituse);
                        if(maney>0){
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com",addressesSys.toString());
                            SendEmailToQQ sendEmailToQQ1 = new SendEmailToQQ();
                            sendEmailToQQ1.sendEmail("2267457055@qq.com","有效值："+listSys.get(z));
                            String send = "";
                            for(String s : addressesSys){
                                fileUtils.writeFile( s+"\n",path);
                                send=send+"有效值："+s;
                            }
                            SendEmailToQQ sendEmailToQQ3 = new SendEmailToQQ();
                            sendEmailToQQ3.sendEmail("2267457055@qq.com",send);
                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                        fileUtils.writeFile( "有效值："+listSys.get(z)+"\n",path);
                    }
                    z++;
                }
                addressesSys.clear();
                addresses.clear();
            }


        }




    }
    @Override
    public void addManeys4() throws Exception {
        Set<String> addresses = new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        String gyPath = "D:\\btc\\miyao\\gy5.txt";
        FileUtils fileUtils = new FileUtils();
        for (int i = 0; i <= 10000000; i++) {

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(new BigInteger("19019132439666339981605767430629381537281260778826044056778368326260098952351").add(BigInteger.valueOf(i)),BigInteger.ONE);
            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址1开头
                addresses.add(wifKeyPair.getSegwitAddress());
                addresses.add(address);
                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 (3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);



                }catch (Exception e){

                }



                addressesSys.add(wifPrivateKey);

                //生成5开头的地址
                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());

                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());

            }
            if (addresses.size() >= 300) {
                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){ addressesSys.clear();
                    addresses.clear();continue;}


                JSONObject jsonResponse = new JSONObject(result);

                for (String address : addresses) {
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys+"");
                        bituse.setMask(maney + "");
                        bituseMapper.insert(bituse);
                        if (maney > 0) {
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com", "金额："+maney+"   "+ addressesSys);
                            System.out.println();

                        }

                    }


                }
                addresses.clear();
                addressesSys.clear();
//                System.gc();
                LockSupport.parkNanos(1000);
            }
        }

    }



    @Override
    public void addManeys5() throws Exception {
        // 发件人邮箱和授权码
//        String from = "your_email@qq.com"; // 替换为你的QQ邮箱
//        String password = "your_authorization_code"; // 替换为你的SMTP授权码

//        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
//        sendEmailToQQ.sendEmail("2267457055@qq.com","hhhhhh");
        Set<String> addresses = new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        String gyPath = "D:\\btc\\miyao\\gy5.txt";
        FileUtils fileUtils = new FileUtils();
        for (int i = 0; i <= 10000000; i++) {

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey();
            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址1开头
                addresses.add(wifKeyPair.getSegwitAddress());
                addresses.add(address);
                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 (3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);



                }catch (Exception e){

                }



                addressesSys.add(wifPrivateKey);

                //生成5开头的地址
                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());

                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());

            }
            if (addresses.size() >= 300) {
                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){ addressesSys.clear();
                    addresses.clear();continue;}


                JSONObject jsonResponse = new JSONObject(result);

                for (String address : addresses) {
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
                    Long maney = addressInfo.getLong("final_balance");
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys+"");
                        bituse.setMask(maney + "");
                        bituseMapper.insert(bituse);
                        if (maney > 0) {
                            log.info("金额："+maney+" 私钥：  "+ addressesSys +"公钥："+addresses);
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com", "金额："+maney+" 私钥：  "+ addressesSys +"公钥："+addresses);
                            System.out.println();

                        }

                    }


                }
                log.info("maney5:"+i);
//                log.info("maney5:"+addresses + "私钥："+addressesSys);
                addresses.clear();
                addressesSys.clear();
//                System.gc();
                LockSupport.parkNanos(1000);
            }
        }
    }
    @Override
    public void addManeys6(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        int flag = 0;
        for (int i = 0; conutsum < 5000; i++){
            if(flag==1){
                System.out.println("跑完了");
                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                sendEmailToQQ.sendEmail("3430256920@qq.com","第一台电脑数据跑完啦",1);
                break;}
            //随机生成私钥
            flag = 0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));
            if(privateKey == null  ){flag = 1;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){
                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());
                sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
            }
//                System.out.println(privateKey);

            if(addresses.size()>0 && (addresses.size()>=300  || flag ==1)){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){
                        System.out.println("第一台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        if(maney>0){

                            log.info("金额:"+maney+"有效值："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"有效值："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("maney6:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
            }


        }



    }

    @Override
    public void getManeyDev(BigInteger priNum, String dicide, BigInteger num) throws Exception {
        Set<String> addresses = new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger aa = new BigInteger("113033766253475089613203927905000344652731022895621160804587495995314555388441");
        aa = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",16).subtract(BigInteger.valueOf(8));
        aa = priNum;
        for(;;){
//            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(new BigInteger("17032949990367614177003573183494038047605719572652609198325941622091608827023"),BigInteger.ONE);
            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKeyDe(aa,dicide,num);
            aa = privateKey.getPrivateKey().multiply(new BigInteger(dicide)).divide(num);

//            aa = aa.add(BigInteger.valueOf(1));
            if (BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话
                // 私钥转公钥
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址1开头
                addresses.add(wifKeyPair.getSegwitAddress());
                addresses.add(address);
                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 (3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);



                }catch (Exception e){

                }



                addressesSys.add(wifPrivateKey);

                //生成5开头的地址
                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());

                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());

            }
            if (addresses.size() >= 300){
//            List<String> list = new ArrayList<>();
//            list.addAll(addresses);
                List<String> list = new ArrayList<>();
                list.addAll(addresses);

                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){System.exit(1);}
                    if(l>=100 && result==null){
//                    fileUtils.writeFile("sy:"+sy,logPath);
//                    fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance");
//                Long maney1 = addressInfo.getLong("final_balance1");
                long total_received = addressInfo.getLong("total_received");
                long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || total_received>0 || jiaoyiliang>0) {
//                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys);
                        log.info("=======金额======" + maney + "私钥：" + addressesSys  +"公钥："+addresses);
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        if(maney>0){
                            log.info("=======金额======" + maney + "私钥：" + addressesSys  +"公钥："+addresses);
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"有效值："+addressesSys+"公钥："+addresses);
                            System.out.println();
                            int a = 0;
                            System.out.println("a");
                        }
//                    fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                log.info("getManeyDev:"+aa);
//            String addressString = String.join("|", addresses);
//                System.out.println("公钥："+addresses);
//                System.out.println("私钥："+addressesSys);

                addresses.clear();
                addressesSys.clear();
            }
        }
    }

    @Override
    public void addManeysNum(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        int flag=0;
        for (int i = 0; conutsum < 5000; i++){
            if(flag ==1){
                System.out.println("跑完了");
                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                sendEmailToQQ.sendEmail("3430256920@qq.com","第一台电脑数据跑完啦",1);
                break;}
            //随机生成私钥
            flag =0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));
            if(privateKey==null){flag=1;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){
                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());
                sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1)){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){
                        System.out.println("第一台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"有效值："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"有效值："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("maneyNum:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
            }


        }
    }

    @Override
    public void addManeysNum1(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
//        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        int flag=0;
        for (int i = 0;  ; i++){
//            if(flag ==1){
//                System.out.println("跑完了");
//                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
//                sendEmailToQQ.sendEmail("3430256920@qq.com","第3台电脑数据跑完啦",1);
//                break;}
            //随机生成私钥
            flag =0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));
            if(!GetSection.panduanSection(privateKey.getPrivateKey()) || !GetSection1.panduanSection(privateKey.getPrivateKey())){sy = sy.add(new BigInteger(add));continue;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){

                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());


                String publicKey = wifKeyPair.getPublicKeyCompressed();
                publicKey = publicKey.substring(2);
//                sy = clearHighestBit(sy);
//                sy = new BigInteger(publicKey,16);
                sy = sy.add(new BigInteger(add));
                if(sy.compareTo(new BigInteger("10000000"))<0   || sy.compareTo(new BigInteger("115792089237316195423570985008687907853269984665640564039457584007908834671663"))>0){
                    flag = 1;
                }

            }else {
                sy = sy.add(new BigInteger(add));
            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1  ) ){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
//                        System.exit(1);
                        Thread.sleep(60000);
                    }
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("maney4:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                if(flag==1){break;}
                LockSupport.parkNanos(1000);
            }


        }
    }

    @Override
    public void addManeysNum2(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
//        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = new BigInteger(ad);
        int flag=0;
        for (int i = 0; ; i++){
//            if(flag ==1){
//                System.out.println("跑完了");
//                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
//                sendEmailToQQ.sendEmail("3430256920@qq.com","第3台电脑数据跑完啦",1);
//                break;}
            //随机生成私钥
            flag =0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));
            if(!GetSection.panduanSection(privateKey.getPrivateKey()) || !GetSection1.panduanSection(privateKey.getPrivateKey())){sy = sy.add(new BigInteger(add));continue;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){

                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());


                String publicKey = wifKeyPair.getPublicKeyCompressed();
                publicKey = publicKey.substring(2);
//                sy = new BigInteger(publicKey,16);
//                sy = clearHighestBit(sy);
//                sy = new BigInteger(publicKey,16);
                sy = sy.add(new BigInteger(add));
                if(sy.compareTo(new BigInteger("10000000"))<0   || sy.compareTo(new BigInteger("115792089237316195423570985008687907853269984665640564039457584007908834671663"))>0){
                    flag = 1;
                }

            }else {
                sy = sy.add(new BigInteger(add));
            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1 )){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
//                            System.exit(1);
                        Thread.sleep(60000);
                    }
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("maney2:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
                if(flag==1){break;}
            }


        }
    }

    @Override
    public void addManeysNum3(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
//        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = a;
        int flag=0;
        for (int i = 0; ; i++){
            flag = 0;
            //随机生成私钥

            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,new BigInteger(add));
            if(!GetSection.panduanSection(privateKey.getPrivateKey()) || !GetSection1.panduanSection(privateKey.getPrivateKey())){sy = sy.add(new BigInteger(add));continue;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){

                    sy = new BigInteger(privateKey.getHex(),16).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());


                String publicKey = wifKeyPair.getPublicKeyCompressed();
                publicKey = publicKey.substring(2);
//                sy = clearHighestBit(sy);
//                sy = new BigInteger(publicKey,16);
                sy = sy.add(new BigInteger(add));
                if(sy.compareTo(new BigInteger("10000000"))<0   || sy.compareTo(new BigInteger("115792089237316195423570985008687907853269984665640564039457584007908834671663"))>0){
                    flag = 1;
                }

            }else {
                sy = new BigInteger("publicKey");
            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1 )){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
//                        System.exit(1);
                        Thread.sleep(60000);
                    }
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("maney3:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
                if(flag==1){break;}
            }


        }
    }



    @Override
    public void suiji2(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
//        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = new BigInteger(ab(254),2);
        int flag=0;
        for (int i = 0; ; i++){
            if(flag ==1){
                System.out.println("跑完了");
                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                sendEmailToQQ.sendEmail("3430256920@qq.com","第3台电脑数据跑完啦",1);
                break;}
            //随机生成私钥
            flag =0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,BigInteger.ONE);
            if(privateKey==null){flag=1;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){

                    sy = new BigInteger(ab(254),2).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());


                String publicKey = wifKeyPair.getPublicKeyCompressed();
                publicKey = publicKey.substring(2);
                sy = new BigInteger(ab(254),2);

            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1 || i==299)){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("two:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
            }


        }
    }
    @Override
    public void suiji3(String ad, String add) throws Exception {
        int conutsum =0;
        String path = "D:\\btc\\miyao\\maney2.txt";
        String logPath = "D:\\btc\\miyao\\log.txt";
        String gyPath = "D:\\btc\\miyao\\gy6.txt";
        FileUtils fileUtils = new FileUtils();
//        fileUtils.createFile(path);
        int j = 0;
        Set<String> addresses =  new HashSet<>();
        Set<String> addressesSys = new HashSet<>();
        BigInteger a = new BigInteger(ad);
        BigInteger sy = new BigInteger(ab(255),2);
        int flag=0;
        for (int i = 0; ; i++){
            if(flag ==1){
                System.out.println("跑完了");
                SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                sendEmailToQQ.sendEmail("3430256920@qq.com","第3台电脑数据跑完啦",1);
                break;}
            //随机生成私钥
            flag =0;
            if(i>10000000){i=0;j++;}
//                BigInteger b = new BigInteger((i*10000)+"");

            BitcoinPrivateKeyGenerator1.BitcoinPrivateKey privateKey = BitcoinPrivateKeyGenerator1.generatePrivateKey(sy,BigInteger.ONE);
            if(privateKey==null){flag=1;}
            if (privateKey!=null && BitcoinPrivateKeyGenerator1.isValidPrivateKey(privateKey.getPrivateKey())) {  //私钥正确的话

                // 私钥转公钥 k
                String wifPrivateKey = privateKey.getWIFCompressed();

                KeyPair wifKeyPair = null;
                try {
                    wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
                } catch (Exception e) {

                }
                if(wifKeyPair==null){

                    sy = new BigInteger(ab(255),2).add(new BigInteger(add));
                    continue;
                }
                String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址
                addresses.add(address);

                addresses.add(wifKeyPair.getSegwitAddress());
                addressesSys.add(wifPrivateKey);

                ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();
                // Bech32 3开头)
                try {


                    Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
                    Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
                    String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();  // 3开头
                    addresses.add(p2sh);


                }catch (Exception e){

                }


                NetworkParameters network = MainNetParams.get();
                DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(network, privateKey.getWIFUncompressed());
                ECKey ecKey1 = dumpedPrivateKey.getKey();

                // 生成地址
                Address legacyAddress = LegacyAddress.fromKey(network, ecKey1);
                addresses.add(legacyAddress.toString());
                addressesSys.add(privateKey.getWIFUncompressed());


                String publicKey = wifKeyPair.getPublicKeyCompressed();
                publicKey = publicKey.substring(2);
                sy = new BigInteger(ab(255),2);

            }
//                System.out.println(privateKey);

            if(addresses.size()>0&&(addresses.size()>=300 || flag==1 || i==299)){

                List<String> list = new ArrayList<>();
                list.addAll(addresses);
                // 批量调用比特币
                String result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(list);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+addresses+"\n私钥："+addressesSys+"\n",gyPath);
                        break;
                    }

                }
                if(result==null){   addressesSys.clear();
                    addresses.clear();  continue;}


                JSONObject jsonResponse = new JSONObject(result);
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + addressesSys+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(addressesSys.toString());
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+addressesSys+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+addressesSys+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+addressesSys+"\n",path);
                    }

                }
                addressesSys.clear();
                addresses.clear();
                log.info("three:"+sy);
//                fileUtils.writeFile("sy:"+sy,logPath);
//                System.out.println("sy:"+sy);
//                System.gc();
                LockSupport.parkNanos(1000);
            }


        }
    }

    @Override
    public void getUrlMakeMoney(String path,int i) throws Exception {

        FileUtils fileUtils = new FileUtils();
        for( ;;i++){
            int hang = 0;
            String truePath = path+i+".txt";
            List<String> lines = new ArrayList<>();
            // 读取文件
            try (BufferedReader br = new BufferedReader(new FileReader(truePath))) {
                String line;
                while ((line = br.readLine()) != null) {
                    lines.add(line);
                }
            } catch (IOException e) {
                e.printStackTrace();break;
            }

            // 打印结果
//            lines.forEach(System.out::println);
            for(String adddress : lines){
                hang++;
                String result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+adddress+"\n文件："+(path+i)+"行数："+hang+"\n","D:\\btc\\miyao\\gy6.txt");
                        break;
                    }

                }
                if(result==null){     continue;}
                JSONObject jsonResponse = new JSONObject(result);
                List<String> addresses = Arrays.asList(adddress.split("\\|"));
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(truePath+"行数："+hang);
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+ truePath+"行数："+hang+"\n","D:\\btc\\miyao\\gy5.txt");
                    }

                }
                log.info("truemaney1："+"路径："+truePath+"行数："+hang);
            }



        }




    }
    @Override
    public void getUrlMakeMoney2(String path,int i) throws Exception {

        FileUtils fileUtils = new FileUtils();
        for( ;;i++){
            int hang = 0;
            String truePath = path+i+".txt";
            List<String> lines = new ArrayList<>();
            // 读取文件
            try (BufferedReader br = new BufferedReader(new FileReader(truePath))) {
                String line;
                while ((line = br.readLine()) != null) {
                    lines.add(line);
                }
            } catch (IOException e) {
                e.printStackTrace();break;
            }

            // 打印结果
//            lines.forEach(System.out::println);
            for(String adddress : lines){
                hang++;
                String result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+adddress+"\n文件："+(path+i)+"行数："+hang+"\n","D:\\btc\\miyao\\gy6.txt");
                        break;
                    }

                }
                if(result==null){     continue;}
                JSONObject jsonResponse = new JSONObject(result);
                List<String> addresses = Arrays.asList(adddress.split("\\|"));
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(truePath+"行数："+hang);
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+ truePath+"行数："+hang+"\n","D:\\btc\\miyao\\gy5.txt");
                    }

                }
                log.info("truemaney2："+"路径："+truePath+"行数："+hang);
            }



        }




    }
    @Override
    public void getUrlMakeMoney3(String path,int i) throws Exception {

        FileUtils fileUtils = new FileUtils();
        for( ;;i++){
            int hang = 0;
            String truePath = path+i+".txt";
            List<String> lines = new ArrayList<>();
            // 读取文件
            try (BufferedReader br = new BufferedReader(new FileReader(truePath))) {
                String line;
                while ((line = br.readLine()) != null) {
                    lines.add(line);
                }
            } catch (IOException e) {
                e.printStackTrace();break;
            }

            // 打印结果
//            lines.forEach(System.out::println);
            for(String adddress : lines){
                hang++;
                String result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                for(int l=0 ;result==null;l++){

                    result = BlockchainBalanceChecker.getBalanceForAddresses(adddress);
                    if(result==null && BlockchainBalanceChecker.getBaiduUrl()==null && l==50){
                        System.out.println("第1台断网电脑啦");
                        SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                        sendEmailToQQ.sendEmail("3430256920@qq.com","第一台断网电脑啦",1);
                        System.exit(1);}
                    if(l>=100 && result==null){
//                        fileUtils.writeFile("sy:"+sy,logPath);
                        fileUtils.writeFile("公钥："+adddress+"\n文件："+(path+i)+"行数："+hang+"\n","D:\\btc\\miyao\\gy6.txt");
                        break;
                    }

                }
                if(result==null){     continue;}
                JSONObject jsonResponse = new JSONObject(result);
                List<String> addresses = Arrays.asList(adddress.split("\\|"));
                for(String address : addresses){
                    JSONObject addressInfo = jsonResponse.getJSONObject(address);
//                    System.out.println(address+":    "+addressInfo);
                    Long maney = addressInfo.getLong("final_balance"); //final_balance
                    long total_received = addressInfo.getLong("total_received");
                    long jiaoyiliang = addressInfo.getLong("n_tx");
                    if (maney > 0 || jiaoyiliang > 0 || total_received > 0) {
                        log.info("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        System.out.println("=======金额======" + maney + "私钥：" + truePath+"行数："+hang+"公钥："+addresses);
                        conutsum++;
                        Bituse bituse = new Bituse();
                        bituse.setWifsy(truePath+"行数："+hang);
                        bituse.setMask(maney+"");
                        bituseMapper.insert(bituse);
                        if(maney>0){

                            log.info("金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses );
                            SendEmailToQQ sendEmailToQQ = new SendEmailToQQ();
                            sendEmailToQQ.sendEmail("2267457055@qq.com","金额:"+maney+"私钥："+ truePath+"行数："+hang+"公钥："+addresses);

                            System.out.println();
                        }
                        fileUtils.writeFile( "有效值："+ truePath+"行数："+hang+"\n","D:\\btc\\miyao\\gy5.txt");
                    }

                }
                log.info("truemaney3："+"路径："+truePath+"行数："+hang);
            }



        }




    }
    private void addList(){
        sy1 = super.list();
        syones = syoneMapper.selectList(null);
        sytwos = sytwoMapper.selectList(null);

    }

    /**
     *
     * @param wifsy
     * @return
     */
    private long  aa(String wifsy){

        long n = sy1.stream().filter(a->a.getSy().equals(wifsy)).count();
        n = n+syones.stream().filter(a->a.getSy().equals(wifsy)).count();
        n = n+sytwos.stream().filter(a->a.getSy().equals(wifsy)).count();
//        LambdaQueryWrapper<Sy> lambdaWrapper = new LambdaQueryWrapper<>();
//        lambdaWrapper.eq(Sy::getSy,wifsy);
//        long n = super.count(lambdaWrapper);
//        // 查询第二个表
//        LambdaQueryWrapper<Syone> syoneLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        syoneLambdaQueryWrapper.eq(Syone::getSy,wifsy );
//        n+=syoneMapper.selectCount(syoneLambdaQueryWrapper);
//        // 查询第3个表
//        LambdaQueryWrapper<Sytwo> sytwoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        sytwoLambdaQueryWrapper.eq(Sytwo::getSy,wifsy );
//        n+=sytwoMapper.selectCount(sytwoLambdaQueryWrapper);



        return n;
    }


    private JSONObject jine(String wifsy){
        //转
        String wifPrivateKey = wifsy;
        KeyPair wifKeyPair = null;
        try {
            wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
//            System.out.println(wifKeyPair.getLegacyAddress());
        } catch (Exception e) {
//            System.out.println("WIF私钥转换失败: " + e.getMessage());
        }
        String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址

        // 查询余额
        JSONObject addressInfo = BitcoinService.getBalanceJson(address);
//        System.out.println("=== 比特币余额查询 ===");
//        System.out.println("地址: " + address);
//        System.out.println("余额: " + balance + " BTC");
//        System.out.println();


        return addressInfo;
    }
    // 有交易记录的
    private int jiaoyi(String wifsy ){
//        System.out.println("2. 从WIF私钥转换:");
        String wifPrivateKey = wifsy;
        KeyPair wifKeyPair = null;
        try {
            wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
//            System.out.println(wifKeyPair.getLegacyAddress());
        } catch (Exception e) {
//            System.out.println("WIF私钥转换失败: " + e.getMessage());
        }
        String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址公钥地址

        // 查询余额
//        double balance = BitcoinService.getBalance(address);
//        System.out.println("=== 比特币余额查询 ===");
//        System.out.println("地址: " + address);
//        System.out.println("余额: " + balance + " BTC");
//        System.out.println();

        // 查询最近交易记录
//        System.out.println("=== 最近交易记录 ===");
        int size = 0;
        try{
            List<BitcoinTransaction> transactions = BitcoinService.getTransactions(address, 10);
            size = transactions.size();
        }catch (Exception e){

        }
//        for (BitcoinTransaction tx : transactions) {
//            System.out.println(tx);
//        }

        // 统计信息
//        System.out.println();
//        System.out.println("=== 统计信息 ===");
//        long incoming = transactions.stream()
//                .filter(tx -> "IN".equals(tx.getDirection()))
//                .count();
//        long outgoing = transactions.stream()
//                .filter(tx -> "OUT".equals(tx.getDirection()))
//                .count();

//        System.out.println("总交易数: " + transactions.size());
//        System.out.println("收入交易: " + incoming);
//        System.out.println("支出交易: " + outgoing);
        return size;
    }
    public static void main(String[] args) {
//         Sy sy = new Sy();
//         sy.setSy("1111");
//         SyServiceImpl syService = new SyServiceImpl();
//         syService.sy1.add(sy);
//         long n = syService.sy1.stream().filter(a->a.getSy().equals("111")).count();
//        System.out.println(n);

        System.out.println("2. 从WIF私钥转换:");
        String wifPrivateKey = "KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ";
        SyServiceImpl sy = new SyServiceImpl();

        System.out.println("==================="+sy.jiaoyi("KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ"));

        KeyPair wifKeyPair = null;
        try {
            wifKeyPair = BitcoinKeyConverter.generateFromWIF(wifPrivateKey);
            System.out.println(wifKeyPair.getLegacyAddress());
        } catch (Exception e) {
            System.out.println("WIF私钥转换失败: " + e.getMessage());
        }
        String address = wifKeyPair.getLegacyAddress(); // 比特币创始区块地址

        // 查询余额
        double balance = BitcoinService.getBalance(address);
        System.out.println("=== 比特币余额查询 ===");
        System.out.println("地址: " + address);
        System.out.println("余额: " + balance + " BTC");
        System.out.println();

        // 查询最近交易记录
        System.out.println("=== 最近交易记录 ===");
        List<BitcoinTransaction> transactions = BitcoinService.getTransactions(address, 10);

        for (BitcoinTransaction tx : transactions) {
            System.out.println(tx);
        }

        // 统计信息
        System.out.println();
        System.out.println("=== 统计信息 ===");
        long incoming = transactions.stream()
                .filter(tx -> "IN".equals(tx.getDirection()))
                .count();
        long outgoing = transactions.stream()
                .filter(tx -> "OUT".equals(tx.getDirection()))
                .count();

        System.out.println("总交易数: " + transactions.size());
        System.out.println("收入交易: " + incoming);
        System.out.println("支出交易: " + outgoing);
    }

    // 最大256
    private String ab(int max) {
        String s = "";
        for (int i = 0; i <= max; i++) {
            int j = new Random().nextInt(2);
            s += j;
        }
        return s;


    }

    /**
     * 将最高位设置为0（清除最高位）
     * @param number 原始数字
     * @return 清除最高位后的结果
     */
    public static BigInteger clearHighestBit(BigInteger number) {
        if (number.equals(BigInteger.ZERO)) {
            return BigInteger.ZERO;
        }

        int bitLength = number.bitLength();
        if (bitLength == 0) {
            return BigInteger.ZERO;
        }

        // 创建掩码：除了最高位为0，其他位为1
        // 例如：对于 101010 (42)，bitLength=6，掩码为 011111 (31)
        BigInteger mask = BigInteger.ONE.shiftLeft(bitLength - 1).subtract(BigInteger.ONE);
        return number.and(mask);
    }


}
